Skip to content

[Commuter Mileage Exclusion] [R1] Display and enforce fixed distance exclusions#93848

Open
fedirjh wants to merge 89 commits into
Expensify:mainfrom
fedirjh:commuter-exclusions-app
Open

[Commuter Mileage Exclusion] [R1] Display and enforce fixed distance exclusions#93848
fedirjh wants to merge 89 commits into
Expensify:mainfrom
fedirjh:commuter-exclusions-app

Conversation

@fedirjh

@fedirjh fedirjh commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Implements the App-side slice of the workspace commuter exclusion feature (App issue #642599). PHP-side (Web-Expensify) lands in https://github.com/Expensify/Web-Expensify/pull/53798.

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/642599
$ https://github.com/Expensify/Expensify/issues/651462
PROPOSAL:

Tests

  1. Open a workspace that has commuter Exclusions set with fixedDistance = 1.
  2. Create a distance expense from a 4.49 mi mapped route on that workspace.
  3. Verify on the confirmation step: the three-line breakdown shows under the Distance row (Original 4.49 mi / Removed 1.00 mi / Reimbursable 3.49 mi) and the amount reflects 3.49 × rate.
  4. Submit. Verify the transaction report shows the system message "Removed 1.00 commuter miles based on workspace distance settings." and the expense detail page also shows the breakdown.
  5. Verify :
    • When every workspace has exclusions, only Map and GPS tabs appear in DistanceRequestStartPage.
    • When some workspaces have exclusions:
      • All four distance tabs (Map / Manual / GPS / Odometer) appear
      • From a workspace without exclusions, switching the Manual or Odometer step and pressing Next surfaces blocking modal.
  • Verify that no errors appear in the JS console

Offline tests

  1. Toggle network off, create a distance expense on an exclusion workspace.
  2. Verify the optimistic breakdown and the optimistic system action render immediately.
  3. Toggle network on, verify the server response confirms the values without flicker.
  4. Repeat with the network failing the request — verify the optimistic transaction merge and the optimistic system action both revert.

QA Steps

Same as Tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Screenshot 2026-06-30 at 11 03 59 AM Screenshot 2026-06-30 at 11 04 04 AM Screenshot 2026-06-29 at 4 51 47 PM Screenshot 2026-06-29 at 4 53 53 PM Screenshot 2026-06-29 at 5 09 48 PM Screenshot 2026-06-29 at 5 09 58 PM Screenshot 2026-06-29 at 5 10 26 PM
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

fedirjh added 6 commits June 17, 2026 14:07
Foundation for the commuter exclusion feature:
- TransactionCustomUnit gains commuterExclusion, reimbursableDistance,
  commuterExclusionType, and commuterExclusionMethod so the App can
  carry the PHP-computed exclusion metadata through Onyx.
- Policy gains the commuterExclusions config object (method,
  fixedDistance, fixedDistanceUnit) so feature gating and the
  optimistic client-side compute can read it.
- CONST.COMMUTER_EXCLUSIONS namespaces the method/type enums; a new
  COMMUTER_EXCLUSION report action type and a
  POLICYCHANGELOG_UPDATE_COMMUTER_EXCLUSIONS policy-change-log type
  are registered for the system message and workspace audit log.
- en.ts adds the three-line breakdown labels, the manual/odometer
  blocked error copy, and the system-message fallback.
Add a DistanceWithCommuterExclusion component that reads
comment.customUnit.{quantity,commuterExclusion,reimbursableDistance,
distanceUnit} and renders a three-line breakdown (original distance,
removed commute distance, reimbursable distance). The component
renders nothing when commuterExclusion is not set or non-positive.

Mount it next to the existing DistanceField in
TransactionDetailsFields (the confirmation / IOURequestStepConfirmation
surface) and after the rate row in MoneyRequestView (the expense
detail / history surface), so both creation and post-creation views
show the same breakdown.
- DistanceRequestStartPage hides the Manual and Odometer tabs when
  every workspace the user belongs to has commuterExclusions
  configured. If at least one workspace lacks exclusions, all four
  tabs stay visible (the user can still pick that workspace).
- useConfirmationValidation: allow zero-amount submission when the
  transaction carries a positive commuterExclusion, so a fully
  excluded distance expense (reimbursable = 0) can still be submitted
  in the split-bill-edit branch. The existing distance-request guard
  already handles the create branch.
- OriginalMessage gains OriginalMessageCommuterExclusion ({distance,
  unit}) keyed under CONST.REPORT.ACTIONS.TYPE.COMMUTER_EXCLUSION so
  callers reading the original message are properly typed.
- ReportActionsUtils.getCommuterExclusionMessage formats the system
  message via the existing distance.commuterExclusion.systemMessage
  i18n key.
- ActionContentRouter renders the COMMUTER_EXCLUSION action as a
  ReportActionItemBasicMessage, matching the existing pattern used
  for plaid/company-card system messages.

The COMMUTER_EXCLUSION action type is already in
CONST.REPORT.ACTIONS.TYPE and therefore in the supportedActionTypes
set built dynamically in ReportActionsUtils, so it is treated as a
visible chat action without further changes.
When the destination policy has a fixedDistance commuter exclusion
configured (method === "fixedDistance" with a positive fixedDistance),
createDistanceRequest now writes:

- A merge onto the optimistic transaction that fills the four new
  comment.customUnit fields (commuterExclusion, reimbursableDistance,
  commuterExclusionMethod) and sets modifiedAmount / modifiedMerchant
  from the reimbursable distance, so the three-line breakdown and the
  reduced amount render instantly without waiting on the server.
- An optimistic COMMUTER_EXCLUSION report action posted to
  reportActions_${chatReportID} (pendingAction: ADD), so the system
  message renders instantly too. ActionContentRouter picks this up
  and renders the localized breakdown.

Failure data reverts both side effects (transaction fields cleared,
optimistic action removed). For commuterExclusions undefined and for
the not-yet-supported homeAndOffice method, behavior is unchanged.

Adds buildOptimisticCommuterExclusionReportAction in ReportUtils
following the existing buildOptimisticCancelPaymentReportAction
pattern.
When the destination policy has commuterExclusions configured, the
user is no longer allowed to submit a manual or odometer distance
expense — the exclusion is computed off the mapped route, so the
mapped flow is the only correct entry. Show a localized form error
explaining why, instead of silently accepting an entry that the
backend wouldn't apply exclusions to.

This complements the tab-hiding in DistanceRequestStartPage (which
only hides the tabs when *every* workspace the user belongs to has
exclusions); when the user has any non-exclusion workspace, the tabs
stay visible but selecting an exclusion workspace on submission
surfaces this error.
@melvin-bot

melvin-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

Hey, I noticed you changed src/languages/en.ts in a PR from a fork. For security reasons, translations are not generated automatically for PRs from forks.

If you want to automatically generate translations for other locales, an Expensify employee will have to:

  1. Look at the code and make sure there are no malicious changes.
  2. Run the Generate static translations GitHub workflow. If you have write access and the K2 extension, you can simply click: [this button]

Alternatively, if you are an external contributor, you can run the translation script locally with your own OpenAI API key. To learn more, try running:

npx ts-node ./scripts/generateTranslations.ts --help

Typically, you'd want to translate only what you changed by running npx ts-node ./scripts/generateTranslations.ts --compare-ref main

fedirjh added 22 commits June 17, 2026 16:29
Remove the top-level COMMUTER_EXCLUSIONS object and use the existing
COMMUTER_EXCLUSION_METHOD and COMMUTER_EXCLUSION_TYPE constants within
CONST.POLICY instead.
Add getCommuterExclusionBreakdown to compute the excluded commuter distance and
reimbursable distance (from the transaction or previewed from the policy), and
getDistanceUnitLabel to return the translated, pluralized unit label.
Render the distance field as "Distance · Original: X" with the reimbursable
distance as the main value and a "Removed X commuter" line via the shared
DistanceWithCommuterExclusion component, on both the confirmation page and the
expense view. Add the supporting translation strings.
Base the distance request amount on the reimbursable distance after the commuter
exclusion, and build the optimistic transaction fields and system action on
creation. Derive the quantity from the route distance when it isn't populated
yet so the exclusion is reflected immediately for route-based requests.
Build the commuter exclusion and fixed-distance report action messages from a
preformatted distance, and render the commuter exclusion message as HTML linking
to the workspace distance settings.
…references. Update distance request handling to calculate reimbursable distance using server-side logic instead of optimistic actions.
For distance requests, always use the computed distanceRequestAmount
since it accounts for commuter exclusions and rate changes. This avoids
stale iouAmount values that don't reflect the current commuter exclusion.
- Return commuterExclusionBreakdown from useDistanceRequestState
- Create commuterExclusionData in MoneyRequestConfirmationList with
  proper unit fallbacks to handle undefined cases
- Update DistanceField to display commuter exclusion UI using the
  computed breakdown, with fallback for unit prop
When commuter exclusion applies, display the reimbursable distance
(not the full distance) in the merchant text so it matches the
calculated amount.
In offline mode, the transaction may not have commuterExclusion stored
yet. Fall back to computing it from the policy's commuterExclusions
config, enabling instant display of commuter exclusion breakdown
before the server response.
Move quantity derivation into getCommuterExclusionBreakdown and let
getDistanceForDisplay render the reimbursable distance via an optional
commuterExclusionData param, removing duplicated formatting across
MoneyRequestView and DistanceField.
… original distance

Share the display-unit formatting between getDistanceForDisplay,
MoneyRequestView, and DistanceField instead of duplicating ad-hoc
toFixed formatting.
Add isCommuterDistance flag and delegate the unit word to
getDistanceUnitLabel, replacing duplicated commuter distance
formatting in DistanceWithCommuterExclusion and ReportActionsUtils.
Updated the useDistanceRequestState hook to utilize commuterExclusionData instead of commuterExclusionBreakdown for improved clarity and consistency. Adjusted related components to reflect this change, ensuring proper data flow and display for distance requests.
@marufsharifi

Copy link
Copy Markdown
Contributor

@heyjennahay heyjennahay requested review from JmillsExpensify and removed request for heyjennahay July 13, 2026 12:13
@Gonals Gonals requested review from marufsharifi and removed request for QichenZhu July 13, 2026 13:36
@Gonals

Gonals commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Assigned.

@fedirjh, some conflicts

@marufsharifi

marufsharifi commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari

@marufsharifi

Copy link
Copy Markdown
Contributor

I am reviewing and testing the code changes.

@github-actions

Copy link
Copy Markdown
Contributor

🚧 JmillsExpensify has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

This comment has been minimized.

@marufsharifi

Copy link
Copy Markdown
Contributor

@fedirjh, could you please take a look? We can still see all the tabs even after deleting the newly created workspace.

RF-1.mp4

@marufsharifi

Copy link
Copy Markdown
Contributor

@fedirjh, I still can't see the Removed 1.00 commuter miles system message in workspace chat.

RF-2.mp4

Copy link
Copy Markdown
Contributor

Still waiting for the beta to take effect on my account to test.

@fedirjh

fedirjh commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

I still can't see the Removed 1.00 commuter miles system message in workspace chat.

@marufsharifi This should be posted in the transaction report, I have updated the test to mention that.

could you please take a look? We can still see all the tabs even after deleting the newly created workspace.

This is fixed now.

@marufsharifi

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@marufsharifi

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4651d1f530

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +377 to +380
if (typeof existingCustomUnit?.quantity === 'number') {
routeDistance = existingCustomUnit.quantity;
} else if (routeDistanceInMeters !== undefined) {
routeDistance = convertDistanceUnit(routeDistanceInMeters, requestDistanceUnit);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Prefer the fresh route distance for exclusions

When a map/GPS route is recalculated after a commuter exclusion has already been applied, callers pass the new routeDistanceMeters while also spreading the existing customUnit, which now contains the previous quantity. This branch prefers that stale quantity, so reimbursableDistance and modifiedAmount stay based on the old route instead of the newly calculated one until the server response corrects it. Prefer the fresh route distance when it is supplied, or overwrite quantity before this calculation.

Useful? React with 👍 / 👎.

Comment on lines +63 to +67
const [shouldHideManualAndOdometerTabs] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {
selector: (allPolicies) => {
const activeGroupPolicies = getActivePolicies(allPolicies ?? null, login).filter(isGroupPolicy);
return activeGroupPolicies.length > 0 && activeGroupPolicies.every((activePolicy) => !!activePolicy.commuterExclusions);
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Scope tab hiding to the selected policy

This hides the manual and odometer tabs whenever all active group policies have commuter exclusions, regardless of what this distance request is actually targeting. A user with only commuter-exclusion workspaces can still create valid personal/P2P or self-DM manual distance expenses, but those flows have policy undefined/personal and the tabs become unreachable before the later per-policy guard can make that distinction.

Useful? React with 👍 / 👎.

@github-actions

Copy link
Copy Markdown
Contributor

🚧 JmillsExpensify has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

Copy link
Copy Markdown
Contributor

🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
Built from App PR #93848.

Android 🤖 iOS 🍎
⏩ SKIPPED ⏩ ⏩ SKIPPED ⏩
The build for Android was skipped The build for iOS was skipped
Web 🕸️
https://93848.pr-testing.expensify.com
Web

👀 View the workflow run that generated this build 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants